import fishcms.Post
import fishcms.PostTopSet
import fishcms.Post
import fishcms.PostTopSet
import fishcms.Tag
import fishcms.Category

class BootStrap {

    def init = { servletContext ->

        initTestData()


    }
    def destroy = {
    }

    private void initTestData() {
        Tag tag1 = new Tag(name: 'grails');
        Tag tag2 = new Tag(name: '生活');

        tag1.save()
        tag2.save()

        Category it = new Category(name: 'IT');
        Category life = new Category(name: '人生');

        it.save()
        life.save()


        Post a1 = new Post(
                title: "t1",
                content: 'content1',
                category: it,
                topSet: new PostTopSet(top: true, abolishedDate: new Date(2016 - 1970, 1, 1)))
        a1.addToTags(tag1)
        a1.addToTags(tag2)
        a1.save()

        for (i in 0..50) {
            Post a2 = new Post(title: "t" + i, content: 'content' + i, category: life)
            a2.author = "author" + i
            if (i%2 == 0) {
                a2.topSet = new PostTopSet(top: true,abolishedDate: new Date())
            }

            a2.save()
        }




    }
}
